﻿namespace TodoSoft.Reporting
{
	/// <summary>
	/// Bound report field to recordset's data field using some aggregation function.
	/// </summary>
	public class ReportDataField : ReportField
	{
		public string PropertyName { get; set; }
		public ReportDataFieldTypes Type { get; set; }

		public static ReportDataField First(string propertyName)
		{
			return new ReportDataField {PropertyName = propertyName, Type = ReportDataFieldTypes.First};
		}

		public static ReportDataField RunningValue(string propertyName)
		{
			return new ReportDataField { PropertyName = propertyName, Type = ReportDataFieldTypes.RunningValue };
		}

		public static ReportDataField Sum(string propertyName)
		{
			return new ReportDataField { PropertyName = propertyName, Type = ReportDataFieldTypes.Sum };
		}

		internal static ReportField First(string propertyName, int width, string caption)
		{
			return new ReportDataField { 
				PropertyName = propertyName, 
				Type = ReportDataFieldTypes.First, 
				Caption = caption,
				Width = width};
		}

		internal static ReportField Sum(string propertyName, int width, string caption)
		{
			return new ReportDataField {
				PropertyName = propertyName,
				Type = ReportDataFieldTypes.Sum,
				Caption = caption,
				Width = width
			}; 
		}

		internal static ReportField Max(string propertyName, int width, string caption)
		{
			return new ReportDataField
			{
				PropertyName = propertyName,
				Type = ReportDataFieldTypes.Max,
				Caption = caption,
				Width = width
			};
		}

		internal static ReportField Min(string propertyName, int width, string caption)
		{
			return new ReportDataField
			{
				PropertyName = propertyName,
				Type = ReportDataFieldTypes.Min,
				Caption = caption,
				Width = width
			};
		}

		internal static ReportField RunningValue(string propertyName, int width, string caption)
		{
			return new ReportDataField
			{
				PropertyName = propertyName,
				Type = ReportDataFieldTypes.RunningValue,
				Caption = caption,
				Width = width
			};
		}
	}

	public enum ReportDataFieldTypes
	{
		First,
		Sum,
		RunningValue,
		Max,
		Min
	}
}